home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / cli / MemPri.lha / MemPri.c next >
Encoding:
C/C++ Source or Header  |  1993-08-18  |  2.3 KB  |  56 lines

  1. /*
  2.     Change priority of a selected memory block
  3.     By Barry McConnell, bmccnnll@unix1.tcd.ie
  4.     Public Domain - do what you like with it!
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <proto/exec.h>
  9. #include <exec/execbase.h>
  10. #include <exec/nodes.h>
  11. #include <exec/memory.h>
  12.  
  13. extern struct ExecBase *SysBase;
  14. struct MemHeader *chunk;
  15. int count, block, pri;
  16.  
  17. int main(int argc, char *argv[])
  18. {
  19. printf("MemPri by Barry McConnell\n\nBlock     Address   Size      Free      Priority  Name\n");
  20.  
  21. for (chunk = (struct MemHeader *)(SysBase -> MemList.lh_Head), count = 0;  /* walk through memory list */
  22.         chunk -> mh_Node.ln_Succ; chunk = (struct MemHeader *)(chunk -> mh_Node.ln_Succ), count++)
  23.     printf("%-10d$%-9x%-10d%-10d%3d       %s\n", count, (int)(chunk -> mh_Lower) - sizeof(struct MemHeader),
  24.             ((int)(chunk -> mh_Upper) - (int)(chunk -> mh_Lower) + sizeof(struct MemHeader)) / 1024,
  25.             chunk -> mh_Free / 1024, chunk -> mh_Node.ln_Pri, chunk -> mh_Node.ln_Name);
  26.  
  27. if (argc == 3)  /* correct number of arguments */
  28.     {
  29.     block = pri = -999;  /* scanf won't change these if the user enters garbage */
  30.     sscanf(argv[1], "%d", &block);  /* get first argument */
  31.     sscanf(argv[2], "%d", &pri);  /* second argument */
  32.     if ((block == -999) || (pri == -999))  /* both valid? */
  33.         printf("\nIllegal argument\n");
  34.     else
  35.         if ((block < 0) || (block >= count) || (pri < -128) || (pri > 127))  /* too big or small? */
  36.             printf("\nArgument out of range\n");
  37.     else
  38.         {
  39.         Disable();  /* because we're going to do some really nasty stuff */
  40.         for (chunk = (struct MemHeader *)(SysBase -> MemList.lh_Head), count = block; count;
  41.                 chunk = (struct MemHeader *)(chunk -> mh_Node.ln_Succ), count--)  /* find selected chunk */
  42.             ;
  43.         Remove((struct Node *)chunk);  /* temporarily remove it from the memory list */
  44.         chunk -> mh_Node.ln_Pri = pri;  /* change its priority */
  45.         Enqueue(&(SysBase -> MemList), (struct Node *)chunk);  /* put back in correct position */
  46.         Enable();
  47.         printf("\nChanged block %d to priority %d\n", block, pri);
  48.         }
  49.     }
  50. else
  51.     if (argc > 1)  /* user probably knows what he wants if he gave no arguments */
  52.         printf("\nUsage: MemPri <block number> <new priority>\n");
  53.  
  54. return 0;
  55. }
  56.